package BaiDu;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main1 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        PriorityQueue<int[]> pq=new PriorityQueue<>(new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if ((o1[0]+o2[0]+o2[1])==(o2[0]+o1[0]+o1[1])){
                    return o1[0]==o2[0]?o1[1]-o2[1]:o1[0]-o2[0];
                }
                return (o1[0]+o2[0]+o2[1])-(o2[0]+o1[0]+o1[1]);
            }
        });
        for (int i = 0; i < n; i++) {
            int a=cin.nextInt(),b=cin.nextInt();
            pq.offer(new int[]{a,b});
        }
        int day=0;
        long res=0;
        while (!pq.isEmpty()){
            int[] cur = pq.poll();
            res+=cur[0]+cur[1]*day;
            if (day%2==1){
                pq.poll();
            }
            day++;
        }
        System.out.println(res);
    }
}
